﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


public partial class Admin_ReaderInfoManage : System.Web.UI.Page
{
    public string orderOftype;
    public string imageurl;
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlDataSource1.SelectCommand = "select readerid as 读者编号,ReaderName as 姓名,Password as 密码,Sex as 性别,ClassID as 班级,Telphone as 号码 ,Email as 邮箱,CreateDate as 创建日期,typename as 类型,Account as 账户余额,Remarks as 备注 from Reader_info ,Reader_type where Reader_info.ReaderType=Reader_Type.ReaderType";



    }
    protected void delete_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in mybookdata.Rows)
        {
            Control ctrl = row.FindControl("CheckBox");

            if ((ctrl as CheckBox).Checked)
            {
                TableCellCollection cell = row.Cells;
                string typeid = cell[1].Text;
                SQL sql = new SQL();
                sql.EXQSQL("delete from book_type where book_info='" + typeid + "'");
            }
        }
        Response.Write("<script language=javascript>alert('删除成功');window.location = 'BookTypeManage.aspx';</script>");
    }

    protected void change_Click(object sender, EventArgs e)
    {
        try
        {
            //int i = Convert.ToInt32(TextBox1.Text);
            SQL sql = new SQL();

            sql.EXQSQL("update reader_info set ReaderID='" + TextBox1.Text + "',ReaderName='" + TextBox2.Text + "',Password='" + TextBox6.Text + "',Sex='" + DropDownList4.SelectedItem.ToString() + "',ClassID='" + TextBox8.Text + "',Telphone='" + TextBox11.Text + "',Email='" + TextBox13.Text + "',Birthday='" + TextBox14.Text + "',LendedNum='0',CreateDate='" + TextBox15.Text + "',Remarks='" + TextBox17.Text + "',ReaderType='" + (DropDownList3.SelectedIndex + 1) + "',Account='" + TextBox16.Text + "' where ReaderID='"+TextBox1.Text+"'");
            Response.Write("<script language=javascript>alert('修改成功');window.location = 'ReaderInfoManage.aspx';</script>");
        }
        catch (System.Exception ex)
        {
            Label1.Text = "警告：您输入有误";
        }
    }

    protected void chaxun_Click(object sender, EventArgs e)
    {

    }
    protected void sureAdd_Click(object sender, EventArgs e)
    {
        string readerid = TypeID.Text;
        string readername = TextBox3.Text;
        string psw = TextBox4.Text;
        string classid = TextBox5.Text;
        string readerType = DropDownList1.SelectedIndex.ToString();
        string tel = TextBox7.Text;
        string email = TextBox30.Text;
        string birthday = TextBox9.Text;
        string createtime = TextBox10.Text = DateTime.Now.ToShortDateString() ;
        string sex = DropDownList2.SelectedItem.Text;
        string account = TextBox12.Text;
        string mark = TextBox20.Text;
        

        try
        {

            SQL sql = new SQL();
            //string publishCompanyID = sql.EXQSQL("SELECT publishCompanyID from publish_Company where publishCompanyName='" + publishCompany + "'");
            //string wetypeid = sql.EXQSQL("SELECT Typeid from Book_Type where TypeName='" + booktype + "'");
            sql.EXQSQL("insert into reader_info values('" + readerid + "','" + readername + "','" + psw + "','" + sex + "','" + classid + "','" + tel + "','" + email + "','" + birthday + "','0','" + createtime + "','" + mark + "','" + (Convert.ToInt32(DropDownList1.SelectedIndex.ToString())+1) + "','" + account + "') ");
            Response.Write("<script language=javascript>alert('增加成功');window.location = 'ReaderInfoManage.aspx';</script>");
        }
        catch (System.Exception ex)
        {
            Label1.Text = "警告：您输入的有误,请检查重新输入";
        }



    }



    protected void Match_Click(object sender, EventArgs e)
    {

    //    string bookname = TextBox3.Text;
    //    UpdataMybookdata UP = new UpdataMybookdata();
    //    string html = UP.GetHTML("https://api.douban.com/v2/book/search?q=" + bookname + "&count=1");
    //    var data = UpdataMybookdata.ScriptDeserialize(html);
    //    TextBox3.Text = data.books[0].title;
    //    string writer = TextBox4.Text = data.books[0].author[0];
    //    string publishdate = TextBox5.Text = data.books[0].pubdate;
    //    string price = TextBox7.Text = data.books[0].price;
    //    string isbn = TextBox13.Text = data.books[0].isbn13;
    //    string atc = TextBox17.Text = data.books[0].summary;
    //    string content = TextBox20.Text = data.books[0].catalog;
    //    Image1.ImageUrl = data.books[0].images.large;

    }
    protected void flash_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in mybookdata.Rows)
        {
            Control ctrl = row.FindControl("CheckBox");

            if ((ctrl as CheckBox).Checked)
            {
                TableCellCollection cell = row.Cells;
                string typeid = cell[1].Text;
                SQL sql = new SQL();



                DataSet ds = sql.getDataset("select * from Reader_info,Reader_type where Reader_type.ReaderType=Reader_info.ReaderType and readerid='"+typeid+"'", "");
                DataTable dt = new DataTable();
                DataRow drow;
                DataRowCollection drc;
                dt = ds.Tables[0];
                drc = dt.Rows;
                for (int i = 0; i < drc.Count; i++)
                {
                    drow = drc[i];
                    string readerid = TextBox1.Text = drow[0].ToString();
                    string readername = TextBox2.Text = drow[1].ToString() ;
                    string psw = TextBox6.Text = drow[2].ToString();
                    string classid = TextBox8.Text=drow[4].ToString();
                    int readerType = DropDownList1.SelectedIndex =(Convert.ToInt32(drow[11].ToString())) - 1;
                    string tel = TextBox11.Text = drow[5].ToString(); ;
                    string email = TextBox13.Text = drow[6].ToString(); ;
                    string birthday = TextBox14.Text = drow[7].ToString(); ;
                    string createtime = TextBox15.Text = drow[9].ToString(); ;
                    //string sex = TextBox14.Text = drow[3].ToString();
                    string account = TextBox16.Text = drow[12].ToString();
                    string mark = TextBox17.Text = drow[10].ToString();

                }


            }

        }
    }
}